package tree.easy;

import tree.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * 257. 二叉树的所有路径
 */
public class binaryTreePaths {
    List<String> res = new ArrayList<>();

    public List<String> binaryTreePaths(TreeNode root) {
        help(root, new StringBuffer());
        return res;
    }

    public void help(TreeNode root, StringBuffer path) {
        if (root != null) {
            StringBuffer nodePath = new StringBuffer(path.toString());
            nodePath.append(root.val);
            if (root.left == null && root.right == null) {
                res.add(nodePath.toString());
            } else {
                nodePath.append("->");
                help(root.left, nodePath);
                help(root.right, nodePath);
            }
        }
    }
}
